import Vue from 'vue'
import VueRouter from 'vue-router'
import Movie from "../views/home/Movie.vue";

Vue.use(VueRouter)

const routes = [
    {path: "/", redirect: "/home"},
    {
        path: '/home',
        name: 'Movie',
        component: Movie,
        children: [
            {path: "/home",redirect:"/home/reying"},
            {
                path: "reying",
                name: "reying",
                component: () => import(/*webpackChunkName:"reying" */ '../views/home/reying.vue')
            },
            {
                path: "yingyuan",
                name: "yingyuan",
                component: () => import(/*webpackChunkName:"yingyuan" */ '../views/home/yingyuan.vue')
            },
            {
                path: "daiying",
                name: "daiying",
                component: () => import(/*webpackChunkName:"daiying" */ '../views/home/daiying.vue')
            },
            {
                path: "jingdian",
                name: "jingdian",
                component: () => import(/*webpackChunkName:"jingdian" */ '../views/home/jingdian.vue')
            },
        ]
    },
    {
        path: '/video',
        name: 'Video',
        component: () => import(/* webpackChunkName: "video" */ '../views/Video.vue')
    },
    {
        path: '/minivideo',
        name: 'MiniVideo',
        component: () => import(/* webpackChunkName: "minivideo" */ '../views/MiniVideo.vue')
    },
    {
        path: '/show',
        name: 'Show',
        component: () => import(/* webpackChunkName: "show" */ '../views/Show.vue')
    },
    {
        path: '/me',
        name: 'Me',
        component: () => import(/* webpackChunkName: "me" */ '../views/Me.vue')
    },
    { //内容页的路由
        path: '/item/:id',//动态路由
        name: 'Item',
        component: () => import(/* webpackChunkName: "item" */ '../views/Item.vue')
    },
    {
        path: '/login',
        name: 'Login',
        component: () => import(/* webpackChunkName: "login" */ '../views/Login.vue')
    },
    {
        path: '/city',
        name: 'City',
        component: () => import(/* webpackChunkName: "city" */ '../views/City.vue')
    },
    {
        path:'*',
        name: 'page404',
        component: () => import(/* webpackChunkName: "page404" */ '../views/Page404.vue')
    }
]

const router = new VueRouter({
    routes
})

router.beforeEach((to,from,next)=>{
    if (to.path=='/me'){
        console.log('12321321')
        console.log(sessionStorage.getItem('loginType'))
        if (sessionStorage.getItem('loginType')=='1'){
            sessionStorage.setItem('loginType','0')
            next();
        }else {
            next('/login');
        }
    }else {
        next();
    }
})

export default router
